Using OLR
vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage , data=train.data)
# took out density since training has 0 d4 and it was not allowing do the plot
p <- plot(vclust)
par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)
#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana
Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)
#library(plyr)
brick <- count(train.data$brick) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "brick")
wood <- count(train.data$wood) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wood")
mixed <- count(train.data$mixed) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "mixed")
TC_mature_soil <- count(train.data$TC_mature_soil) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_mature_soil")
T_construction <- count(train.data$T_construction ) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "T_construction ")
spring <- count(train.data$spring) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "spring")
landfill <- count(train.data$landfill) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "landfill")
garbage <- count(train.data$garbage) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "garbage")
crack <- count(train.data$crack) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "crack")
leaning_wall <- count(train.data$leaning_wall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "leaning_wall")
scars <- count(train.data$scars) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
downward_floor <- count(train.data$downward_floor) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "scars")
tilted <- count(train.data$tilted) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tilted")
conc_rainfall <- count(train.data$conc_rainfall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall")
wastewater <- count(train.data$wastewater) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wastewater")
leak <- count(train.data$leak) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall_water")
septic_tank <- count(train.data$septic_tank) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "septic_tank")
angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
mutate("Percentage"=(freq/106)*100)%>%
mutate("Classifier" = "angle")
EN <- count(train.data$EN) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "EN")
TC <- count(train.data$TC) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "TC")
TC_saprolite_soil <- count(train.data$TC_saprolite_soil ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_saprolite_soil ")
banana <- count(train.data$banana) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "banana")
drainage <- count(train.data$drainage) %>%
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "drainage")
deforestation <- count(train.data$deforestation) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "deforestation")
TC_unstable_structure <- count(train.data$TC_unstable_structure ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_unstable_structure ")
tree <- count(train.data$tree) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tree")
ground_veg <- count(train.data$ground_veg) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "ground_veg")
density <- count(train.data$density) %>% #(79, 415, 36) # d4 =0
mutate ("Percentage"=(freq/132.5)*100)%>%
mutate("Classifier" = "density")
TC_weath_rock <- count(train.data$TC_weath_rock ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_weath_rock ")
fracture <- count(train.data$fracture) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "fracture")
df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil, banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)
df
## x freq Percentage Classifier
## 1 FALSE 33 12.4528302 brick
## 2 TRUE 497 187.5471698 brick
## 3 FALSE 459 173.2075472 wood
## 4 TRUE 71 26.7924528 wood
## 5 FALSE 489 184.5283019 mixed
## 6 TRUE 41 15.4716981 mixed
## 7 FALSE 257 96.9811321 TC_mature_soil
## 8 TRUE 273 103.0188679 TC_mature_soil
## 9 FALSE 220 83.0188679 T_construction
## 10 TRUE 310 116.9811321 T_construction
## 11 FALSE 513 193.5849057 spring
## 12 TRUE 17 6.4150943 spring
## 13 FALSE 330 124.5283019 landfill
## 14 TRUE 200 75.4716981 landfill
## 15 FALSE 350 132.0754717 garbage
## 16 TRUE 180 67.9245283 garbage
## 17 FALSE 437 164.9056604 crack
## 18 TRUE 93 35.0943396 crack
## 19 FALSE 498 187.9245283 leaning_wall
## 20 TRUE 32 12.0754717 leaning_wall
## 21 FALSE 319 120.3773585 DepTaludeAterro
## 22 TRUE 211 79.6226415 DepTaludeAterro
## 23 FALSE 471 177.7358491 scars
## 24 TRUE 59 22.2641509 scars
## 25 FALSE 437 164.9056604 tilted
## 26 TRUE 93 35.0943396 tilted
## 27 FALSE 17 6.4150943 conc_rainfall
## 28 TRUE 513 193.5849057 conc_rainfall
## 29 FALSE 199 75.0943396 wastewater
## 30 TRUE 331 124.9056604 wastewater
## 31 FALSE 355 133.9622642 conc_rainfall_water
## 32 TRUE 175 66.0377358 conc_rainfall_water
## 33 FALSE 526 198.4905660 septic_tank
## 34 TRUE 4 1.5094340 septic_tank
## 35 C 30 28.3018868 angle
## 36 D 132 124.5283019 angle
## 37 E 368 347.1698113 angle
## 38 FALSE 338 127.5471698 EN
## 39 TRUE 192 72.4528302 EN
## 40 FALSE 31 11.6981132 TC
## 41 TRUE 499 188.3018868 TC
## 42 FALSE 441 166.4150943 TC_saprolite_soil
## 43 TRUE 89 33.5849057 TC_saprolite_soil
## 44 FALSE 355 133.9622642 banana
## 45 TRUE 175 66.0377358 banana
## 46 Y 71 40.1810979 drainage
## 47 P 232 131.2959819 drainage
## 48 N 227 128.4663271 drainage
## 49 FALSE 492 185.6603774 deforestation
## 50 TRUE 38 14.3396226 deforestation
## 51 FALSE 515 194.3396226 TC_unstable_structure
## 52 TRUE 15 5.6603774 TC_unstable_structure
## 53 FALSE 218 82.2641509 tree
## 54 TRUE 312 117.7358491 tree
## 55 FALSE 150 56.6037736 ground_veg
## 56 TRUE 380 143.3962264 ground_veg
## 57 d1 67 50.5660377 density
## 58 d2 423 319.2452830 density
## 59 d3 40 30.1886792 density
## 60 FALSE 518 195.4716981 TC_weath_rock
## 61 TRUE 12 4.5283019 TC_weath_rock
## 62 FALSE 529 199.6226415 fracture
## 63 TRUE 1 0.3773585 fracture
TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)
# Equation 1
eq_OLR_01 <- polr(risk ~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.90571356 0.4482420 -2.0205906 2.166108e-02
## woodTRUE 1.19305709 0.3227843 3.6961434 1.094497e-04
## ENTRUE 0.36995285 0.3554549 1.0407870 1.489872e-01
## TC_mature_soilTRUE 0.63590612 0.2158958 2.9454304 1.612529e-03
## T_constructionTRUE 0.72925151 0.3581180 2.0363443 2.085789e-02
## springTRUE -0.19379492 0.6488691 -0.2986657 3.825976e-01
## landfillTRUE -0.12227217 0.3266681 -0.3743009 3.540902e-01
## leakTRUE -0.24443428 0.2349938 -1.0401732 1.491297e-01
## garbageTRUE -0.08640315 0.2886514 -0.2993340 3.823426e-01
## crackTRUE 1.56036886 0.3230498 4.8301188 6.822579e-07
## leaning_wallTRUE 1.41245087 0.4798512 2.9435187 1.622521e-03
## scarsTRUE 3.62424756 0.3269981 11.0833900 7.552161e-29
## downward_floorTRUE 1.05677057 0.3701001 2.8553642 2.149375e-03
## tiltedTRUE 0.95046871 0.3278435 2.8991535 1.870858e-03
## septic_tankTRUE -0.15096733 1.1541543 -0.1308034 4.479654e-01
## conc_rainfallTRUE 1.81064328 0.5714170 3.1686900 7.656380e-04
## wastewaterTRUE 0.84821836 0.2324285 3.6493726 1.314408e-04
## ground_vegTRUE 0.86828266 0.2523118 3.4413081 2.894545e-04
## angleD 0.39301030 0.4680075 0.8397521 2.005237e-01
## angleE 0.46510674 0.5275722 0.8815983 1.889970e-01
## TC_saprolite_soilTRUE 0.22104204 0.2762444 0.8001683 2.118066e-01
## R1|R2 0.92985845 0.9040600 1.0285363 1.518488e-01
## R2|R3 5.13398847 0.9456596 5.4290024 2.833497e-08
## R3|R4 9.79257161 1.0345879 9.4651902 1.465136e-21
stargazer((ctable), type="text", style="default", digits = 2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -0.91 0.45 -2.02 0.02
## woodTRUE 1.19 0.32 3.70 0.0001
## ENTRUE 0.37 0.36 1.04 0.15
## TC_mature_soilTRUE 0.64 0.22 2.95 0.002
## T_constructionTRUE 0.73 0.36 2.04 0.02
## springTRUE -0.19 0.65 -0.30 0.38
## landfillTRUE -0.12 0.33 -0.37 0.35
## leakTRUE -0.24 0.23 -1.04 0.15
## garbageTRUE -0.09 0.29 -0.30 0.38
## crackTRUE 1.56 0.32 4.83 0.0000
## leaning_wallTRUE 1.41 0.48 2.94 0.002
## scarsTRUE 3.62 0.33 11.08 0
## downward_floorTRUE 1.06 0.37 2.86 0.002
## tiltedTRUE 0.95 0.33 2.90 0.002
## septic_tankTRUE -0.15 1.15 -0.13 0.45
## conc_rainfallTRUE 1.81 0.57 3.17 0.001
## wastewaterTRUE 0.85 0.23 3.65 0.0001
## ground_vegTRUE 0.87 0.25 3.44 0.0003
## angleD 0.39 0.47 0.84 0.20
## angleE 0.47 0.53 0.88 0.19
## TC_saprolite_soilTRUE 0.22 0.28 0.80 0.21
## R1| R2 0.93 0.90 1.03 0.15
## R2| R3 5.13 0.95 5.43 0.0000
## R3| R4 9.79 1.03 9.47 0
## ------------------------------------------------------
less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)
Equation 1
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 33|Inf | 3.4657359| 1.139434283|-0.8329091|
## | |Yes|496|Inf | 2.2806062|-0.072612533|-2.0217759|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |458|Inf | 2.2167851|-0.157530203|-2.2670784|
## | |Yes| 71|Inf | 3.5409593| 1.079920156|-0.6097656|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |337|Inf | 1.8959830|-0.415366179|-2.2545759|
## | |Yes|192|Inf | 4.1431347| 0.740400065|-1.4663371|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |257|Inf | 1.9151385|-0.274076420|-2.3685431|
## | |Yes|272|Inf | 2.9139023| 0.251314428|-1.5918936|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |220|Inf | 1.5349354|-0.804372816|-2.9444390|
## | |Yes|309|Inf | 3.6276687| 0.550726841|-1.4863778|
## +-----------------+---+---+----+----------+------------+----------+
## |spring |No |512|Inf | 2.2918898|-0.031252544|-2.0005935|
## | |Yes| 17|Inf | Inf| 0.875468737|-0.3566749|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |329|Inf | 1.8423117|-0.502728414|-2.5422579|
## | |Yes|200|Inf | 4.5951199| 0.847297860|-1.2656664|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |354|Inf | 2.0890110|-0.284387177|-2.2749336|
## | |Yes|175|Inf | 3.0385523| 0.575364145|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |350|Inf | 2.0476928|-0.252765807|-2.3312039|
## | |Yes|179|Inf | 3.2015843| 0.490022496|-1.3449091|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.371176035|-2.6790627|
## | |Yes| 93|Inf | 3.8177123| 2.508437147|-0.2814125|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.116832917|-2.1255326|
## | |Yes| 32|Inf | Inf| 2.708050201|-0.1251631|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |318|Inf | 1.7771607|-1.398128819|-4.1367653|
## | |Yes|211|Inf | 5.3471075| 3.000719815|-0.8540775|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |470|Inf | 2.1972246|-0.248072934|-2.2454267|
## | |Yes| 59|Inf | Inf| 4.060443011|-0.4480247|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1375053|-0.399734433|-2.4386134|
## | |Yes| 93|Inf | 4.5217886| 3.102342009|-0.5978370|
## +-----------------+---+---+----+----------+------------+----------+
## |septic_tank |No |525|Inf | 2.3194631|-0.011428696|-1.9221766|
## | |Yes| 4|Inf | Inf| 1.098612289|-1.0986123|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |199|Inf | 1.6522579|-0.460215623|-2.9391619|
## | |Yes|330|Inf | 3.0445224| 0.268263987|-1.5453591|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |150|Inf | 1.3451363|-1.265666373|-2.5365787|
## | |Yes|379|Inf | 3.1218141| 0.445205437|-1.7315003|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 30|Inf | Inf|-0.268263987| -Inf|
## | |D |132|Inf | 3.7612001| 0.762140052|-1.3581235|
## | |E |367|Inf | 1.9934627|-0.246471804|-2.0733253|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |440|Inf | 2.2753894|-0.100083459|-2.0541237|
## | |Yes| 89|Inf | 2.6270811| 0.480972661|-1.3723081|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)
f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)
stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.62673029 0.5293559 -1.18394885 1.182167e-01
## woodTRUE 1.13513842 0.3339284 3.39934645 3.377355e-04
## ENTRUE 0.39002345 0.3725482 1.04690748 1.475711e-01
## TC_mature_soilTRUE 0.60913390 0.2263222 2.69144601 3.557151e-03
## T_constructionTRUE 0.82676166 0.3651228 2.26433888 1.177664e-02
## landfillTRUE -0.23144077 0.3324566 -0.69615343 2.431664e-01
## leakTRUE -0.37734521 0.2417603 -1.56082399 5.928264e-02
## garbageTRUE -0.08766765 0.2914036 -0.30084615 3.817659e-01
## crackTRUE 1.58000415 0.3270524 4.83104339 6.790970e-07
## leaning_wallTRUE 1.48227476 0.4906912 3.02078917 1.260584e-03
## treeTRUE -0.46223047 0.2376718 -1.94482676 2.589792e-02
## downward_floorTRUE 0.98664984 0.3716125 2.65504987 3.964834e-03
## tiltedTRUE 0.87246750 0.3259929 2.67633909 3.721565e-03
## ground_vegTRUE 0.88122670 0.2741453 3.21445088 6.534714e-04
## scarsTRUE 3.64162056 0.3341436 10.89836889 5.867095e-28
## mixedTRUE 0.23630421 0.4917956 0.48049272 3.154385e-01
## conc_rainfallTRUE 1.52382524 0.6076985 2.50753506 6.078826e-03
## wastewaterTRUE 0.72159287 0.2391811 3.01693050 1.276742e-03
## angleD 0.29609771 0.4715647 0.62790480 2.650332e-01
## angleE 0.39302852 0.5307278 0.74054630 2.294843e-01
## bananaTRUE 0.29392333 0.2470592 1.18968777 1.170846e-01
## drainage.L 0.71097588 0.2711687 2.62189527 4.372115e-03
## drainage.Q 0.03053974 0.1860008 0.16419145 4.347902e-01
## TC_saprolite_soilTRUE 0.20875355 0.2830427 0.73753388 2.303989e-01
## TCTRUE 0.02300363 0.4820458 0.04772083 4.809694e-01
## deforestationTRUE 0.37058436 0.3942701 0.93992521 1.736280e-01
## R1|R2 0.63293154 1.0990887 0.57586939 2.823517e-01
## R2|R3 4.99470264 1.1214981 4.45359887 4.222140e-06
## R3|R4 9.70510422 1.2065145 8.04391847 4.350521e-16
stargazer((ctable), type="text", style="default", digits=2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -0.63 0.53 -1.18 0.12
## woodTRUE 1.14 0.33 3.40 0.0003
## ENTRUE 0.39 0.37 1.05 0.15
## TC_mature_soilTRUE 0.61 0.23 2.69 0.004
## T_constructionTRUE 0.83 0.37 2.26 0.01
## landfillTRUE -0.23 0.33 -0.70 0.24
## leakTRUE -0.38 0.24 -1.56 0.06
## garbageTRUE -0.09 0.29 -0.30 0.38
## crackTRUE 1.58 0.33 4.83 0.0000
## leaning_wallTRUE 1.48 0.49 3.02 0.001
## treeTRUE -0.46 0.24 -1.94 0.03
## downward_floorTRUE 0.99 0.37 2.66 0.004
## tiltedTRUE 0.87 0.33 2.68 0.004
## ground_vegTRUE 0.88 0.27 3.21 0.001
## scarsTRUE 3.64 0.33 10.90 0
## mixedTRUE 0.24 0.49 0.48 0.32
## conc_rainfallTRUE 1.52 0.61 2.51 0.01
## wastewaterTRUE 0.72 0.24 3.02 0.001
## angleD 0.30 0.47 0.63 0.27
## angleE 0.39 0.53 0.74 0.23
## bananaTRUE 0.29 0.25 1.19 0.12
## drainage.L 0.71 0.27 2.62 0.004
## drainage.Q 0.03 0.19 0.16 0.43
## TC_saprolite_soilTRUE 0.21 0.28 0.74 0.23
## TCTRUE 0.02 0.48 0.05 0.48
## deforestationTRUE 0.37 0.39 0.94 0.17
## R1| R2 0.63 1.10 0.58 0.28
## R2| R3 4.99 1.12 4.45 0.0000
## R3| R4 9.71 1.21 8.04 0
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 33|Inf | 3.4657359| 1.139434283|-0.8329091|
## | |Yes|496|Inf | 2.2806062|-0.072612533|-2.0217759|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |458|Inf | 2.2167851|-0.157530203|-2.2670784|
## | |Yes| 71|Inf | 3.5409593| 1.079920156|-0.6097656|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |337|Inf | 1.8959830|-0.415366179|-2.2545759|
## | |Yes|192|Inf | 4.1431347| 0.740400065|-1.4663371|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |257|Inf | 1.9151385|-0.274076420|-2.3685431|
## | |Yes|272|Inf | 2.9139023| 0.251314428|-1.5918936|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |220|Inf | 1.5349354|-0.804372816|-2.9444390|
## | |Yes|309|Inf | 3.6276687| 0.550726841|-1.4863778|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |329|Inf | 1.8423117|-0.502728414|-2.5422579|
## | |Yes|200|Inf | 4.5951199| 0.847297860|-1.2656664|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |354|Inf | 2.0890110|-0.284387177|-2.2749336|
## | |Yes|175|Inf | 3.0385523| 0.575364145|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |350|Inf | 2.0476928|-0.252765807|-2.3312039|
## | |Yes|179|Inf | 3.2015843| 0.490022496|-1.3449091|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.371176035|-2.6790627|
## | |Yes| 93|Inf | 3.8177123| 2.508437147|-0.2814125|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.116832917|-2.1255326|
## | |Yes| 32|Inf | Inf| 2.708050201|-0.1251631|
## +-----------------+---+---+----+----------+------------+----------+
## |tree |No |217|Inf | 1.8691461|-0.518205731|-2.1323639|
## | |Yes|312|Inf | 2.7932080| 0.349673748|-1.7805862|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |470|Inf | 2.1972246|-0.248072934|-2.2454267|
## | |Yes| 59|Inf | Inf| 4.060443011|-0.4480247|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1375053|-0.399734433|-2.4386134|
## | |Yes| 93|Inf | 4.5217886| 3.102342009|-0.5978370|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |150|Inf | 1.3451363|-1.265666373|-2.5365787|
## | |Yes|379|Inf | 3.1218141| 0.445205437|-1.7315003|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |318|Inf | 1.7771607|-1.398128819|-4.1367653|
## | |Yes|211|Inf | 5.3471075| 3.000719815|-0.8540775|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed |No |488|Inf | 2.2626685|-0.082013152|-2.0430739|
## | |Yes| 41|Inf | 3.6888795| 1.003302109|-0.8823892|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |199|Inf | 1.6522579|-0.460215623|-2.9391619|
## | |Yes|330|Inf | 3.0445224| 0.268263987|-1.5453591|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 30|Inf | Inf|-0.268263987| -Inf|
## | |D |132|Inf | 3.7612001| 0.762140052|-1.3581235|
## | |E |367|Inf | 1.9934627|-0.246471804|-2.0733253|
## +-----------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.295926142|-2.2749336|
## | |Yes|175|Inf | 3.7553692| 0.600253434|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage |Y | 71|Inf | 0.9360934|-1.929909808|-4.2484952|
## | |P |231|Inf | 2.2512918|-0.448950220|-2.5980493|
## | |N |227|Inf | 3.7932395| 0.978811089|-1.2386584|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |440|Inf | 2.2753894|-0.100083459|-2.0541237|
## | |Yes| 89|Inf | 2.6270811| 0.480972661|-1.3723081|
## +-----------------+---+---+----+----------+------------+----------+
## |TC |No | 31|Inf | Inf| 0.597837001|-1.9095425|
## | |Yes|498|Inf | 2.2613197|-0.040166042|-1.9141615|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation |No |491|Inf | 2.3183690| 0.044814016|-1.8979009|
## | |Yes| 38|Inf | 2.4567358|-0.653926467|-2.1400662|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)
f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)
# x=TRUE, y=TRUE used by resid() below
eq_OLR_03 <- polr(risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## woodTRUE 1.15648174 0.3185486 3.6304724 1.414515e-04
## TC_mature_soilTRUE 0.62400820 0.2152496 2.8989980 1.871787e-03
## T_constructionTRUE 0.75432691 0.2874781 2.6239459 4.345879e-03
## landfillTRUE -0.16666490 0.2924984 -0.5697977 2.844074e-01
## crackTRUE 1.61467343 0.3136191 5.1485177 1.312765e-07
## leaning_wallTRUE 1.54595590 0.4810655 3.2136077 6.553931e-04
## treeTRUE -0.46139881 0.2281912 -2.0219832 2.158904e-02
## downward_floorTRUE 0.86008313 0.3569470 2.4095539 7.986018e-03
## tiltedTRUE 0.87868289 0.3180930 2.7623458 2.869383e-03
## ground_vegTRUE 0.87649783 0.2665764 3.2879800 5.045450e-04
## scarsTRUE 3.59485212 0.3307962 10.8672704 8.253272e-28
## conc_rainfallTRUE 1.48533326 0.6003969 2.4739187 6.682004e-03
## wastewaterTRUE 0.69634674 0.2315639 3.0071472 1.318560e-03
## bananaTRUE 0.30843014 0.2383932 1.2937873 9.786945e-02
## drainage.L 0.72110787 0.2652309 2.7187930 3.276030e-03
## drainage.Q 0.03998779 0.1845090 0.2167255 4.142112e-01
## R1|R2 0.77628657 0.5833004 1.3308522 9.161882e-02
## R2|R3 5.06168730 0.6389593 7.9217674 1.170790e-15
## R3|R4 9.73234897 0.7584622 12.8316855 5.448374e-38
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 1.16 0.32 3.63 0.0001
## TC_mature_soilTRUE 0.62 0.22 2.90 0.002
## T_constructionTRUE 0.75 0.29 2.62 0.004
## landfillTRUE -0.17 0.29 -0.57 0.28
## crackTRUE 1.61 0.31 5.15 0.0000
## leaning_wallTRUE 1.55 0.48 3.21 0.001
## treeTRUE -0.46 0.23 -2.02 0.02
## downward_floorTRUE 0.86 0.36 2.41 0.01
## tiltedTRUE 0.88 0.32 2.76 0.003
## ground_vegTRUE 0.88 0.27 3.29 0.001
## scarsTRUE 3.59 0.33 10.87 0
## conc_rainfallTRUE 1.49 0.60 2.47 0.01
## wastewaterTRUE 0.70 0.23 3.01 0.001
## bananaTRUE 0.31 0.24 1.29 0.10
## drainage.L 0.72 0.27 2.72 0.003
## drainage.Q 0.04 0.18 0.22 0.41
## R1| R2 0.78 0.58 1.33 0.09
## R2| R3 5.06 0.64 7.92 0
## R3| R4 9.73 0.76 12.83 0
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |458|Inf | 2.2167851|-0.157530203|-2.2670784|
## | |Yes| 71|Inf | 3.5409593| 1.079920156|-0.6097656|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |257|Inf | 1.9151385|-0.274076420|-2.3685431|
## | |Yes|272|Inf | 2.9139023| 0.251314428|-1.5918936|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |220|Inf | 1.5349354|-0.804372816|-2.9444390|
## | |Yes|309|Inf | 3.6276687| 0.550726841|-1.4863778|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |329|Inf | 1.8423117|-0.502728414|-2.5422579|
## | |Yes|200|Inf | 4.5951199| 0.847297860|-1.2656664|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.371176035|-2.6790627|
## | |Yes| 93|Inf | 3.8177123| 2.508437147|-0.2814125|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.116832917|-2.1255326|
## | |Yes| 32|Inf | Inf| 2.708050201|-0.1251631|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |217|Inf | 1.8691461|-0.518205731|-2.1323639|
## | |Yes|312|Inf | 2.7932080| 0.349673748|-1.7805862|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |470|Inf | 2.1972246|-0.248072934|-2.2454267|
## | |Yes| 59|Inf | Inf| 4.060443011|-0.4480247|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1375053|-0.399734433|-2.4386134|
## | |Yes| 93|Inf | 4.5217886| 3.102342009|-0.5978370|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |150|Inf | 1.3451363|-1.265666373|-2.5365787|
## | |Yes|379|Inf | 3.1218141| 0.445205437|-1.7315003|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |318|Inf | 1.7771607|-1.398128819|-4.1367653|
## | |Yes|211|Inf | 5.3471075| 3.000719815|-0.8540775|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |199|Inf | 1.6522579|-0.460215623|-2.9391619|
## | |Yes|330|Inf | 3.0445224| 0.268263987|-1.5453591|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.295926142|-2.2749336|
## | |Yes|175|Inf | 3.7553692| 0.600253434|-1.3862944|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 71|Inf | 0.9360934|-1.929909808|-4.2484952|
## | |P |231|Inf | 2.2512918|-0.448950220|-2.5980493|
## | |N |227|Inf | 3.7932395| 0.978811089|-1.2386584|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)
f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)
eq_OLR_04 <- polr(risk~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, data= train.data
, method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_04))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## woodTRUE 1.14758241 0.3181970 3.6065153 1.414515e-04
## TC_mature_soilTRUE 0.63984536 0.2135162 2.9967067 1.871787e-03
## T_constructionTRUE 0.65505791 0.2286261 2.8651934 4.345879e-03
## crackTRUE 1.58826996 0.3096955 5.1284889 2.844074e-01
## leaning_wallTRUE 1.55015405 0.4803406 3.2271980 1.312765e-07
## treeTRUE -0.45684073 0.2279439 -2.0041804 6.553931e-04
## downward_floorTRUE 0.84385038 0.3558386 2.3714414 2.158904e-02
## tiltedTRUE 0.84197154 0.3112963 2.7047273 7.986018e-03
## ground_vegTRUE 0.86602360 0.2658905 3.2570681 2.869383e-03
## scarsTRUE 3.59185674 0.3303761 10.8720233 5.045450e-04
## conc_rainfallTRUE 1.46566613 0.5982549 2.4499025 8.253272e-28
## wastewaterTRUE 0.71774873 0.2285195 3.1408641 6.682004e-03
## bananaTRUE 0.30541953 0.2383271 1.2815139 1.318560e-03
## drainage.L 0.71938846 0.2653657 2.7109321 9.786945e-02
## drainage.Q 0.03554308 0.1843865 0.1927641 3.276030e-03
## R1|R2 0.76790003 0.5819513 1.3195263 4.142112e-01
## R2|R3 5.04693842 0.6369895 7.9231108 9.161882e-02
## R3|R4 9.71773339 0.7567001 12.8422523 1.170790e-15
stargazer((ctable), type="text", style="default", digits=2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 1.15 0.32 3.61 0.0001
## TC_mature_soilTRUE 0.64 0.21 3.00 0.002
## T_constructionTRUE 0.66 0.23 2.87 0.004
## crackTRUE 1.59 0.31 5.13 0.28
## leaning_wallTRUE 1.55 0.48 3.23 0.0000
## treeTRUE -0.46 0.23 -2.00 0.001
## downward_floorTRUE 0.84 0.36 2.37 0.02
## tiltedTRUE 0.84 0.31 2.70 0.01
## ground_vegTRUE 0.87 0.27 3.26 0.003
## scarsTRUE 3.59 0.33 10.87 0.001
## conc_rainfallTRUE 1.47 0.60 2.45 0
## wastewaterTRUE 0.72 0.23 3.14 0.01
## bananaTRUE 0.31 0.24 1.28 0.001
## drainage.L 0.72 0.27 2.71 0.10
## drainage.Q 0.04 0.18 0.19 0.003
## R1| R2 0.77 0.58 1.32 0.41
## R2| R3 5.05 0.64 7.92 0.09
## R3| R4 9.72 0.76 12.84 0
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |458|Inf | 2.2167851|-0.157530203|-2.2670784|
## | |Yes| 71|Inf | 3.5409593| 1.079920156|-0.6097656|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |257|Inf | 1.9151385|-0.274076420|-2.3685431|
## | |Yes|272|Inf | 2.9139023| 0.251314428|-1.5918936|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |220|Inf | 1.5349354|-0.804372816|-2.9444390|
## | |Yes|309|Inf | 3.6276687| 0.550726841|-1.4863778|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.371176035|-2.6790627|
## | |Yes| 93|Inf | 3.8177123| 2.508437147|-0.2814125|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.116832917|-2.1255326|
## | |Yes| 32|Inf | Inf| 2.708050201|-0.1251631|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |217|Inf | 1.8691461|-0.518205731|-2.1323639|
## | |Yes|312|Inf | 2.7932080| 0.349673748|-1.7805862|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |470|Inf | 2.1972246|-0.248072934|-2.2454267|
## | |Yes| 59|Inf | Inf| 4.060443011|-0.4480247|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1375053|-0.399734433|-2.4386134|
## | |Yes| 93|Inf | 4.5217886| 3.102342009|-0.5978370|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |150|Inf | 1.3451363|-1.265666373|-2.5365787|
## | |Yes|379|Inf | 3.1218141| 0.445205437|-1.7315003|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |318|Inf | 1.7771607|-1.398128819|-4.1367653|
## | |Yes|211|Inf | 5.3471075| 3.000719815|-0.8540775|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |199|Inf | 1.6522579|-0.460215623|-2.9391619|
## | |Yes|330|Inf | 3.0445224| 0.268263987|-1.5453591|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.295926142|-2.2749336|
## | |Yes|175|Inf | 3.7553692| 0.600253434|-1.3862944|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 71|Inf | 0.9360934|-1.929909808|-4.2484952|
## | |P |231|Inf | 2.2512918|-0.448950220|-2.5980493|
## | |N |227|Inf | 3.7932395| 0.978811089|-1.2386584|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_05 <- polr(risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_05))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.8017886 0.4377363 -1.8316702 3.350028e-02
## woodTRUE 1.1613958 0.3177068 3.6555579 1.283116e-04
## TC_mature_soilTRUE 0.6085804 0.2121088 2.8691898 2.057624e-03
## T_constructionTRUE 0.6419487 0.2247481 2.8563036 2.143025e-03
## crackTRUE 1.5777380 0.3068486 5.1417470 1.360978e-07
## leaning_wallTRUE 1.3822538 0.4747772 2.9113738 1.799216e-03
## scarsTRUE 3.6266114 0.3255316 11.1405835 3.979809e-29
## downward_floorTRUE 0.9673063 0.3562411 2.7153137 3.310651e-03
## tiltedTRUE 0.9480315 0.3117904 3.0406052 1.180516e-03
## conc_rainfallTRUE 1.7871103 0.5651682 3.1620856 7.832175e-04
## wastewaterTRUE 0.7985826 0.2225401 3.5884889 1.663001e-04
## ground_vegTRUE 0.9140495 0.2394432 3.8173966 6.743363e-05
## R1|R2 0.5402921 0.7011528 0.7705767 2.204789e-01
## R2|R3 4.7054026 0.7502138 6.2720824 1.781254e-10
## R3|R4 9.3381685 0.8459276 11.0389685 1.239311e-28
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.80 0.44 -1.83 0.03
## woodTRUE 1.16 0.32 3.66 0.0001
## TC_mature_soilTRUE 0.61 0.21 2.87 0.002
## T_constructionTRUE 0.64 0.22 2.86 0.002
## crackTRUE 1.58 0.31 5.14 0.0000
## leaning_wallTRUE 1.38 0.47 2.91 0.002
## scarsTRUE 3.63 0.33 11.14 0
## downward_floorTRUE 0.97 0.36 2.72 0.003
## tiltedTRUE 0.95 0.31 3.04 0.001
## conc_rainfallTRUE 1.79 0.57 3.16 0.001
## wastewaterTRUE 0.80 0.22 3.59 0.0002
## ground_vegTRUE 0.91 0.24 3.82 0.0001
## R1| R2 0.54 0.70 0.77 0.22
## R2| R3 4.71 0.75 6.27 0
## R3| R4 9.34 0.85 11.04 0
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |brick |No | 33|Inf | 3.4657359| 1.139434283|-0.8329091|
## | |Yes|496|Inf | 2.2806062|-0.072612533|-2.0217759|
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |458|Inf | 2.2167851|-0.157530203|-2.2670784|
## | |Yes| 71|Inf | 3.5409593| 1.079920156|-0.6097656|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |257|Inf | 1.9151385|-0.274076420|-2.3685431|
## | |Yes|272|Inf | 2.9139023| 0.251314428|-1.5918936|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |220|Inf | 1.5349354|-0.804372816|-2.9444390|
## | |Yes|309|Inf | 3.6276687| 0.550726841|-1.4863778|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.371176035|-2.6790627|
## | |Yes| 93|Inf | 3.8177123| 2.508437147|-0.2814125|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.116832917|-2.1255326|
## | |Yes| 32|Inf | Inf| 2.708050201|-0.1251631|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |318|Inf | 1.7771607|-1.398128819|-4.1367653|
## | |Yes|211|Inf | 5.3471075| 3.000719815|-0.8540775|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |470|Inf | 2.1972246|-0.248072934|-2.2454267|
## | |Yes| 59|Inf | Inf| 4.060443011|-0.4480247|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1375053|-0.399734433|-2.4386134|
## | |Yes| 93|Inf | 4.5217886| 3.102342009|-0.5978370|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |199|Inf | 1.6522579|-0.460215623|-2.9391619|
## | |Yes|330|Inf | 3.0445224| 0.268263987|-1.5453591|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |150|Inf | 1.3451363|-1.265666373|-2.5365787|
## | |Yes|379|Inf | 3.1218141| 0.445205437|-1.7315003|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_06))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.86087665 0.5144253 -1.6734727 4.711714e-02
## woodTRUE 1.08535299 0.3213285 3.3777051 3.654671e-04
## mixedTRUE 0.38972759 0.4795220 0.8127418 2.081830e-01
## ENTRUE 0.55318904 0.3658785 1.5119474 6.527362e-02
## TCTRUE 0.38024390 0.4456450 0.8532440 1.967620e-01
## T_constructionTRUE 0.84705850 0.3520257 2.4062406 8.058823e-03
## landfillTRUE -0.19986692 0.3217770 -0.6211349 2.672554e-01
## leakTRUE -0.11272431 0.2286103 -0.4930851 3.109762e-01
## garbageTRUE -0.06498002 0.2846240 -0.2283013 4.097060e-01
## crackTRUE 1.54152875 0.3203237 4.8124095 7.456070e-07
## leaning_wallTRUE 1.49848450 0.4875674 3.0733893 1.058211e-03
## treeTRUE -0.40806880 0.2299011 -1.7749757 3.795095e-02
## tiltedTRUE 0.97473131 0.3197320 3.0485883 1.149597e-03
## angleD 0.36132644 0.4644558 0.7779566 2.182973e-01
## angleE 0.54417476 0.5232077 1.0400742 1.491527e-01
## ground_vegTRUE 0.94259553 0.2641526 3.5683753 1.796009e-04
## scarsTRUE 3.75664380 0.3300188 11.3831216 2.537502e-30
## conc_rainfallTRUE 1.98575202 0.5738686 3.4602906 2.697964e-04
## wastewaterTRUE 0.74755723 0.2286110 3.2699970 5.377431e-04
## bananaTRUE 0.39123568 0.2412285 1.6218469 5.241806e-02
## R1|R2 1.27656372 1.0519397 1.2135332 1.124630e-01
## R2|R3 5.38728130 1.0835163 4.9720354 3.312681e-07
## R3|R4 9.98448927 1.1662054 8.5615186 5.569520e-18
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.86 0.51 -1.67 0.05
## woodTRUE 1.09 0.32 3.38 0.0004
## mixedTRUE 0.39 0.48 0.81 0.21
## ENTRUE 0.55 0.37 1.51 0.07
## TCTRUE 0.38 0.45 0.85 0.20
## T_constructionTRUE 0.85 0.35 2.41 0.01
## landfillTRUE -0.20 0.32 -0.62 0.27
## leakTRUE -0.11 0.23 -0.49 0.31
## garbageTRUE -0.06 0.28 -0.23 0.41
## crackTRUE 1.54 0.32 4.81 0.0000
## leaning_wallTRUE 1.50 0.49 3.07 0.001
## treeTRUE -0.41 0.23 -1.77 0.04
## tiltedTRUE 0.97 0.32 3.05 0.001
## angleD 0.36 0.46 0.78 0.22
## angleE 0.54 0.52 1.04 0.15
## ground_vegTRUE 0.94 0.26 3.57 0.0002
## scarsTRUE 3.76 0.33 11.38 0
## conc_rainfallTRUE 1.99 0.57 3.46 0.0003
## wastewaterTRUE 0.75 0.23 3.27 0.001
## bananaTRUE 0.39 0.24 1.62 0.05
## R1| R2 1.28 1.05 1.21 0.11
## R2| R3 5.39 1.08 4.97 0.0000
## R3| R4 9.98 1.17 8.56 0
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |brick |No | 33|Inf | 3.4657359| 1.139434283|-0.8329091|
## | |Yes|496|Inf | 2.2806062|-0.072612533|-2.0217759|
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |458|Inf | 2.2167851|-0.157530203|-2.2670784|
## | |Yes| 71|Inf | 3.5409593| 1.079920156|-0.6097656|
## +--------------+---+---+----+----------+------------+----------+
## |mixed |No |488|Inf | 2.2626685|-0.082013152|-2.0430739|
## | |Yes| 41|Inf | 3.6888795| 1.003302109|-0.8823892|
## +--------------+---+---+----+----------+------------+----------+
## |EN |No |337|Inf | 1.8959830|-0.415366179|-2.2545759|
## | |Yes|192|Inf | 4.1431347| 0.740400065|-1.4663371|
## +--------------+---+---+----+----------+------------+----------+
## |TC |No | 31|Inf | Inf| 0.597837001|-1.9095425|
## | |Yes|498|Inf | 2.2613197|-0.040166042|-1.9141615|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |220|Inf | 1.5349354|-0.804372816|-2.9444390|
## | |Yes|309|Inf | 3.6276687| 0.550726841|-1.4863778|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |329|Inf | 1.8423117|-0.502728414|-2.5422579|
## | |Yes|200|Inf | 4.5951199| 0.847297860|-1.2656664|
## +--------------+---+---+----+----------+------------+----------+
## |leak |No |354|Inf | 2.0890110|-0.284387177|-2.2749336|
## | |Yes|175|Inf | 3.0385523| 0.575364145|-1.3862944|
## +--------------+---+---+----+----------+------------+----------+
## |garbage |No |350|Inf | 2.0476928|-0.252765807|-2.3312039|
## | |Yes|179|Inf | 3.2015843| 0.490022496|-1.3449091|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |436|Inf | 2.1620451|-0.371176035|-2.6790627|
## | |Yes| 93|Inf | 3.8177123| 2.508437147|-0.2814125|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.116832917|-2.1255326|
## | |Yes| 32|Inf | Inf| 2.708050201|-0.1251631|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |217|Inf | 1.8691461|-0.518205731|-2.1323639|
## | |Yes|312|Inf | 2.7932080| 0.349673748|-1.7805862|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |436|Inf | 2.1375053|-0.399734433|-2.4386134|
## | |Yes| 93|Inf | 4.5217886| 3.102342009|-0.5978370|
## +--------------+---+---+----+----------+------------+----------+
## |angle |C | 30|Inf | Inf|-0.268263987| -Inf|
## | |D |132|Inf | 3.7612001| 0.762140052|-1.3581235|
## | |E |367|Inf | 1.9934627|-0.246471804|-2.0733253|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |150|Inf | 1.3451363|-1.265666373|-2.5365787|
## | |Yes|379|Inf | 3.1218141| 0.445205437|-1.7315003|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |318|Inf | 1.7771607|-1.398128819|-4.1367653|
## | |Yes|211|Inf | 5.3471075| 3.000719815|-0.8540775|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.6061358|-2.772588722| -Inf|
## | |Yes|512|Inf | 2.5818989| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |199|Inf | 1.6522579|-0.460215623|-2.9391619|
## | |Yes|330|Inf | 3.0445224| 0.268263987|-1.5453591|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |354|Inf | 1.9785928|-0.295926142|-2.2749336|
## | |Yes|175|Inf | 3.7553692| 0.600253434|-1.3862944|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_01, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
## predictedLevel1
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 3 85 5 0
## R3 0 18 59 7
## R4 0 0 11 17
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1
## [1] 0.2678571
predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
## predictedLevel2
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 4 85 4 0
## R3 0 18 62 4
## R4 0 0 11 17
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.2544643
predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_03, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
## predictedLevel3
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 2 85 6 0
## R3 0 18 62 4
## R4 0 0 10 18
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.25
predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_04, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
## predictedLevel4
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 2 85 6 0
## R3 0 19 61 4
## R4 0 0 10 18
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.2544643
predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly
predictedScores5 <- predict(eq_OLR_05, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
## predictedLevel5
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 3 84 6 0
## R3 0 17 60 7
## R4 0 0 9 19
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2589286
predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly
predictedScores6 <- predict(eq_OLR_06, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
## predictedLevel6
## R1 R2 R3 R4
## R1 3 16 0 0
## R2 3 84 6 0
## R3 0 20 59 5
## R4 0 0 12 16
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.2767857
#Table
df2 <- data.frame(
"Equations"=c(1:6),
"Predicted"=c(1-p1,
1-p2,
1-p3,
1-p4,
1-p5,
1-p6
)
)
df2
## Equations Predicted
## 1 1 0.7321429
## 2 2 0.7455357
## 3 3 0.7500000
## 4 4 0.7455357
## 5 5 0.7410714
## 6 6 0.7232143